import { defineStore } from "pinia";
import { postLoginAPI } from '@/apis/login';
import { ref } from "vue";
export const useUserStore = defineStore('user',()=>{
  const userInfo = ref({})

  const getUserInfo = async (data) => {
    const { data: { result } } = await postLoginAPI(data)
    userInfo.value = result
    localStorage.setItem('user', JSON.stringify(result))
  }

  const clearUserInfo = () => {
    localStorage.removeItem('user')
  }
  return {
    userInfo,
    getUserInfo,
    clearUserInfo
  }
},
{
  persist:true
}
)